$(function () {
    obj.init();
});
var obj = new function () {
    "use strict";
    return {
        iRHId: null,
        dataGrid: null,
        dom: {
            addBtn: null,
            delBtn: null,
            search: null,
            default1: null,
        },
        init: function () {
            this.iRHId = xhTool.getQuery('iRHId');
            this.dataGrid = new xhDataGrid($('#list'),'lm/rent/getRenter/'+this.iRHId, {});
            this.dataGrid.parseToolbar().init().activeButton(['bt_list_del'],['bt_setDefault']);
            this.dom.addBtn = $('#bt_list_add');
            this.dom.delBtn = $('#bt_list_del');
            this.dom.default1 = $('#bt_setDefault');

            this.listener();

        },
        listener: function () {
            var $this = this;

            //新建联系人
            $this.dom.addBtn.click(function () {
                $this.funObj().openAddContact();
            });
            //删除联系人
            $this.dom.delBtn.click(function () {
                if (xhExtra.buttonDisabled($(this))) {
                    return false;
                }
                $this.funObj().openDelView();

            });
            //设置默认联系人
            $this.dom.default1.click(function () {
                if (xhExtra.buttonDisabled($(this))) {
                    return false;
                }
                $this.funObj().setDefault();
            });
            //绑定dataGrid监听事件
            this.funObj().bindDgEvent();

        },
        funObj: function () {
            var $this = this;
            return {
                openAddContact: function () {
                    window.top.xhTop.showModal({
                        title: '新建联系人',
                        content: '<iframe src="' + baseUrl + 'lm/rent/renterForm/' + $this.iRHId + ' " style="height: 300px;border-style: none;padding: 0px;width: 100%"></iframe>',
                        button: '提交',
                        backClose: false
                    });
                },
                openDelView: function () {
                    var ids = $this.dataGrid.getSelectValues('iRSId');
                    xhExtra.askChangeStatus('lm/rent/delRenter',{ids:ids},null,null,function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        $this.dataGrid.reload();
                    });
                },
                setDefault: function () {
                    var iRSId = $this.dataGrid.getSelectValue('iRSId');
                    var iRHId =  $this.dataGrid.getSelectValue('iRHId');
                    xhExtra.askChangeStatus('lm/rent/setCharge',{iRSId: iRSId, iRHId: iRHId},null,'确定要设置为负责人吗?',function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        $this.dataGrid.reload();
                    });
                },
                bindDgEvent: function () {
                    $this.dataGrid.onDblClickRow = function (rowIndex, rowData) {
                        window.top.xhTop.showModal({
                            title: '编辑联系人',
                            content: '<iframe src="' + baseUrl + 'lm/rent/renterForm/' + $this.iRHId + '/' + rowData['iRSId'] + '" style="height: 300px;border-style: none;padding: 0px;width: 100%;"></iframe>',
                            button: '提交',
                            backClose: false
                        });
                    };
                }

            }
        }

    }
};